<?php
namespace app\front\controller;

use \app\common\controller\Base;
use \think\Loader;
use \think\View;
use \think\Db;

class Cms extends Base{

    public function _initialize()
    {
        $this->pages  = Loader::model('Pages');
        $configs = Db::table("ig_config")->field("name,value")->where("status",1)->select();
        $this->assign("config",$this->config2arr($configs));
        $user = Loader::model('AccountRegistration');
        $userId = intval(session("u_id"));
        if($userId){
            $user_info = $user->find($userId);
            if($user_info){
                $this->user = $user;
                $this->userId = $userId;
                $this->assign("is_login",true);
                $this->assign("user",$user_info->toArray());
            }else{
                $this->assign("is_login",false);
            }
        }else{
            $this->assign("is_login",false);
        }
    }
    private function config2arr($configs){
        $arr = array();
        foreach($configs as $config){
            $arr[$config['name']] = $config['value'];
        }
        return $arr;
    }
    public function index(){
        return $this->fetch();
    }

    public function pages($id){
        $page = $this->pages->where(['status'=>'Y','keyword_en'=>$id])->find();
        $page['content_cn'] = $this->display($page['content_cn']);
        $this->assign("page",$page);
        return $this->fetch();

    }

    public function register(){


    }


}
